<?php

namespace WeForge\Queue\Connectors;

use HttpClient\Aliyun\Factory;
use Illuminate\Queue\Connectors\ConnectorInterface;
use WeForge\Queue\FnfQueue;

class FnfConnector implements ConnectorInterface
{
    /**
     * Establish a queue connection.
     *
     * @param  array  $config
     *
     * @return \Illuminate\Contracts\Queue\Queue
     */
    public function connect(array $config)
    {
        $client = Factory::serverlessWorkflow([
            'http' => [
                'base_uri' => $config['endpoint'],
            ],
            'access_key_id' => $config['key'],
            'access_key_secret' => $config['secret'],
            'security_token' => $config['security_token'],
        ]);

        return new FnfQueue($client, $config['flow']);
    }
}
